/**
 * 
 */
package com.hfjyz.examination.dao.impl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.hfjyz.examination.dao.UserDao;
import com.hfjyz.examination.domain.UserInfo;

/**
 * 
 */
public class UserDaoImpl extends BaseDaoImpl<UserInfo, Long> implements UserDao {

	public UserDaoImpl() {
		super(UserInfo.class);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hfjyz.examination.dao.UserDao#getByUsername(java.lang.String)
	 */
	@Override
	public UserInfo getByUsername(final String userName) throws Exception {
		return (UserInfo) hibernateTemplate.execute(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				return (UserInfo) session.createCriteria(UserInfo.class)
						.add(Restrictions.naturalId().set("userno", userName))
						.uniqueResult();
			}
		});
	}

}
